import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersist from 'vuex-persist'
Vue.use(Vuex);

const vuexLC = new VuexPersist ({storage: window.localStorage });


export default new Vuex.Store({
  state: {
    loginStatus:false,
    avatar:'',
    gender:'',
    loginUser:{
      id:1,
      phone:'18261163859',
      password:'4297f44b13955235245b2497399d7a93',
      nickname:'明星哥',
      avatar:'https://s-moses.oss-cn-hangzhou.aliyuncs.com/logo/d39edae5-45e0-4603-b61a-0fa61ae8de15.jpeg',
      gender:1,
      brithday:'1999-10-14',
      address:'江苏省常州市',
      banner:'',
      signature:'这是一个签名',
      createTime:'2020-12-16 20:30:31'
    },
    user:{}
  },
  mutations: {
    login(state,user){
      state.loginStatus=true
      state.loginUser=user
      localStorage.setItem('loginUser',JSON.stringify(user))
    },
    visit(state,user){
      state.user=user
    }
    ,
    logout(state){
      state.loginStatus=false
      state.user={}
      localStorage.removeItem('user')
    },
    setAvatar(state, data) {
      state.avatar = data
    },
    // 修改资料
    editUserInfo(state, obj) {
      if (state.user) {
        state.user.nickname = obj.nickname
        state.user.password = obj.password
        state.user.avatar = obj.avatar
        state.user.gender = obj.gender
        state.user.birthday = obj.birthday
        state.user.address = obj.address
        localStorage.setItem('user', JSON.stringify(state.user))
      }
    }
  },
  actions: {},
  modules: {},
  plugins: [vuexLC.plugin]
});
